using System.Web.Mvc;
using Ideaa.Services.Interfaces;
using Microsoft.Practices.Unity;
using Unity.Mvc5;
using Ideaa.Data.Infrastructure;
using System.Data.Entity;
using Ideaa.Data;
using Ideaa.Web.Controllers;
using Ideaa.Services.Services;
using Ideaa.Data.Repositories;

namespace Ideaa.Web.App_Start
{
    public static class UnityConfig
    {
        public static void RegisterComponents()
        {
			var container = new UnityContainer();
            
            // register all your components with the container here
            // it is NOT necessary to register your controllers
            
            // e.g. container.RegisterType<ITestService, TestService>();
            
            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
            container.RegisterType<IUnitOfWork, UnitOfWork>();
            container.RegisterType<DbContext, ApplicationDbContext>(new PerResolveLifetimeManager());

            // repositories
            container.RegisterType<IIdeaRepository, IdeaRepository>();
            container.RegisterType<ISuggestionRepository, SuggestionRepository>();

            // services
            container.RegisterType<IIdeaService, IdeaService>();
            container.RegisterType<ISuggestionService, SuggestionService>();
            container.RegisterType<IVoteService, VoteService>();

            // controllers
            container.RegisterType<AccountController>(new InjectionConstructor());
            //container.RegisterType<IdeaController>(new InjectionConstructor());
        }
    }
}